<?php

namespace app\admin\model;

use fast\Tree;
use think\Model;

class Tip extends Model
{

    // 表名
    protected $name = 'tip';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'status_text'
    ];

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
	
	 public static function getTreeList($selected = [])
    {
        $ruleList = collection(self::where('status', 'normal')->order('id asc')->select())->toArray();
		
		
		$ruleli = json_decode($ruleList[0]['rules'],1);
		
		//print_r($ruleli);die;
        $nodeList = [];
        Tree::instance()->init($ruleli);
		
       // $ruleList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
		//print_r($ruleList);die;
		
		foreach ($ruleli as $k => $v) {
            $nodeList[$v['title']] = $v['title'];
        }
		//print_r($nodeList);die;
        return $nodeList;
    }

}
